Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(public API): expose hashing to curve for BN254 and BLS12-381 #437

Merged
merged 1 commit into from
Jul 19, 2024

Conversation

mratsim
Copy link
Owner

@mratsim mratsim commented Jul 19, 2024

For @Mikerah for differential testing/fuzzing vs https://github.com/hashcloak/bn254-hash-to-curve

AFAIK all crypto libraries use the same internal representation:

  • native-endian 64-bit words (or 32-bit words on 32-bit machines for Constantine )
  • little-endian ordering of limbs withing a BigInt/Field element
  • Montgomery representation with a' = aR (mod p) and R = 2²⁵⁶ (mod p) for BN254 (i.e. the next multiple of the word size)
  • (x, y) ordering of Elliptic curve coordinates

Hence you should be able to cast Constantine <-> Arkworks similar to what I do for Halo2curves here with mem::transmute::<MaybeUninit<bn254_snarks_g1_aff>, ark_bn254::G1Affine>

fn msm(&self, coeffs: &[bn256::Fr], bases: &[bn256::G1Affine]) -> bn256::G1 {
assert_eq!(coeffs.len(), bases.len());
let mut result = MaybeUninit::<bn254_snarks_g1_prj>::uninit();
unsafe {
ctt_bn254_snarks_g1_prj_multi_scalar_mul_fr_coefs_vartime_parallel(
self.0.get_private_context(),
result.as_mut_ptr(),
coeffs.as_ptr() as *const bn254_snarks_fr,
bases.as_ptr() as *const bn254_snarks_g1_aff,
bases.len(),
);
mem::transmute::<MaybeUninit<bn254_snarks_g1_prj>, bn256::G1>(result)
}

@mratsim mratsim added the enhancement :shipit: New feature or request label Jul 19, 2024
@mratsim mratsim merged commit 261f9dd into master Jul 19, 2024
24 checks passed
@mratsim mratsim deleted the expose-h2c branch July 19, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement :shipit: New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant